package com.grandtech.insurance.service.impl;

import com.grandtech.insurance.dao.DbKhyzmxDAO;
import com.grandtech.insurance.dao.SysAdminareaDAO;
import com.grandtech.insurance.domain.SysAdminarea;
import com.grandtech.insurance.service.DbKhyzmxService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DbKhyzmxServiceImpl implements DbKhyzmxService {

    @Autowired
    DbKhyzmxDAO dbKhyzmxDAO;

    @Autowired
    SysAdminareaDAO areaDao;

    @Override
    public SysAdminarea Userlowarea(String code,String desc) {
        SysAdminarea adminareaDO1 = new SysAdminarea();
        adminareaDO1 = areaDao.getByQhdm(code);
        if (adminareaDO1 == null) {
            return new SysAdminarea();
        }
        Map params = new HashMap();
        params.put("qhdm",code);
        params.put("desc",desc);
        Map map = new HashMap();
        List<SysAdminarea> areaShi = null;
        List<SysAdminarea> areaSheng = null;
        if (params.containsKey("desc") && params.get("desc")!=null) {
            areaSheng = areaDao.getLowAreaNew(params);
            for (SysAdminarea adminarea : areaSheng) {
                map.put("qhdm", adminarea.getQhdm());
                areaShi = areaDao.getLowAreaNew(map);
                adminarea.setChildren(areaShi);
            }

        } else {
            areaSheng = areaDao.getLowArea(params);
            for (SysAdminarea adminarea : areaSheng) {
                map.put("qhdm", adminarea.getQhdm());
                areaShi = areaDao.getLowArea(map);
                adminarea.setChildren(areaShi);
            }
        }
        adminareaDO1.setChildren(areaSheng);
        return adminareaDO1;
    }

    @Override
    public SysAdminarea UserlowareaNew(String code) {
        return null;
    }

}
